<?php
class CommandHistory
{
	public $Commands=array();
	public function CommandHistory()
	{
		if(!isset($_SESSION['commands'])||!is_array($_SESSION['commands']))
		{
			$this->Commands=array();
		}
		else 
		{
			$this->Commands=$_SESSION['commands'];
		}
	}
	public function Add($command)
	{
		$command=trim($command);
		if($command!='')
			$this->Commands[]=$command;
		$this->OnlyLatest(10);
	}
	public function Rebuild()
	{
		$_SESSION['commands']=$this->Commands;
	}
	public function OnlyLatest($num)
	{
		$this->Commands=array_slice($this->Commands,-1*$num);
	}
	public function GetLast()
	{
		$num=count($this->Commands);
		if($num==0)
			return null;
		return $this->Commands[$num-1];
	}
}
?>